import { loadReportCellData } from '@/apis/report.js';

export default class ReportInfoManager {
  constructor() {
    this.reportId = -1;
    this.Page = {
      PageWidth: 595, // 报表中页面的默认宽度
      PageHeight: 841, // 报表中页面的默认高度
      InteractiveWidth: 595, // 在交互式呈现器中呈现报表时的页面的默认宽度
      InteractiveHeight: 841, // 在交互式呈现器中呈现报表时的页面的默认高度
      Width: 595, // 报表中页面的默认宽度
      Height: 841, // 报表中页面的默认高度
      Windows: '', //   哪些窗口可挂此报表
      MarginTop: 0, // 报表纸张的边距
      MarginLeft: 0,
      MarginBottom: 0,
      MarginRight: 0,
    };

    // 报表主体样式
    this.Body = {
      Height: 300,
      AllGridViews: [],
      Type: 'Center',
    };
    this.bookCord = null;
  }

  async loadReportCellData(reportId) {
    // 获取存储过程列表
    this.reportId = reportId;
    const res = await loadReportCellData(
      { reportId: this.reportId, CurrentWindowRecordID: '100000004' },
    );
    this.Page.Width = res.report.Width;
    this.Page.PageHeight = res.report.PageHeight;
    this.Page.PageWidth = res.report.PageWidth;
    this.Page.InteractiveWidth = res.report.InteractiveWidth;
    this.Page.InteractiveHeight = res.report.InteractiveHeight;

    this.Page.MarginTop = res.report.MarginTop;
    this.Page.MarginLeft = res.report.MarginLeft;
    this.Page.MarginBottom = res.report.MarginBottom;
    this.Page.MarginRight = res.report.MarginRight;

    this.Body.Height = res.report.CenterSection.Height;
    this.Body.AllGridViews = res.report.CenterSection.AllGridViews;
    const index = this.Body.AllGridViews.findIndex(a => a.Name.indexOf('cord') > -1);
    if (index > -1) {
      this.bookCord = this.Body.AllGridViews.splice(index, 1)[0];
    }
  }
}
